<?php

class View {
	
	public $data = array();
	public $viewSuffix = '.tpl';
	public $tpl;
	
	public function set($varName, $val){
		$this->data[$varName] = $val;
	}
	
	public function render($view = null){
		foreach($this->data as $key=>$val){
			${$key} = $val;
		}
		ob_start();
		
		$view_loc = '';
		if($view == null){
			$where = APP::here();
			$view_loc = ROOT.DS.APP_DIR.DS.'View'.DS.'Pages'.DS.$where['controller'].DS.$where['action'].$this->viewSuffix;
			
		}
		else{
			$view_loc = ROOT.DS.APP_DIR.DS.'View'.DS.'Pages'.DS.$view.$this->viewSuffix;
		}
		
		if(file_exists($view_loc)){
			include($view_loc);
			return ob_get_clean();
		}
		else{
			throwException(new Exception("View file can not found"));
		}
		
		return null;
	}
	
}

?>